import time
from vec import *

WIDTH = 500
HEIGHT = 500
CIRCLE_COLOR = (0, 200, 0)
BACK_COLOR = (0, 0, 0)

class MyCircle:
    def __init__(self, pos, r):
        self.pos = pos
        self.r = r

    def Draw(self):
        screen.draw.filled_circle((self.pos.x, self.pos.y), self.r, CIRCLE_COLOR)

lastTime = time.time()
deltaTime = 0

START_PT = Vec2(WIDTH / 2, HEIGHT / 2)
END_PT = Vec2(WIDTH / 2, HEIGHT / 2)
p = 0
pspd = 0.5
c = MyCircle(START_PT, 20)

def move(start_pt, end_pt):
    global p, c
    has_finished = False

    p += pspd * deltaTime

    if p > 1.0:    
        p = 1.0
        has_finished = True

    c.pos = start_pt * (1 - p) + end_pt * p

    return has_finished
    
def on_mouse_down(pos):
    global START_PT, END_PT, p
    END_PT.x = pos[0]
    END_PT.y = pos[1]
    START_PT = c.pos
    p = 0    

def update():
    global START_PT, END_PT, deltaTime, lastTime, p

    curTime = time.time()
    deltaTime = curTime - lastTime
    lastTime = curTime
    
    if START_PT == END_PT:
        return

    if move(START_PT, END_PT) == True:
        START_PT.x = c.pos.x
        START_PT.y = c.pos.y
        END_PT.x = c.pos.x
        END_PT.y = c.pos.y

def draw():
    screen.clear()
    screen.fill(BACK_COLOR)
    c.Draw()